1 Imports System.Data.SqlClient
2 Public Class frmClassTransfer
3 Dim Status As String
4 Sub fillSession()
5 Try
6 con = New SqlConnection(cs)
7 con.Open()
8 adp = New SqlDataAdapter()
9 adp.SelectCommand = New SqlCommand("SELECT distinct (Session) FROM Student", con)
10 ds = New DataSet("ds")
11 adp.Fill(ds)
12 dtable = ds.Tables(0)
13 cmbSession.Items.Clear()
14 For Each drow As DataRow In dtable.Rows
15 cmbSession.Items.Add(drow(0).ToString())
16 Next
17 Catch ex As Exception
18 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
19 End Try
20 End Sub
21 Sub fillSession1()
22 Try
23 con = New SqlConnection(cs)
24 con.Open()
25 adp = New SqlDataAdapter()
26 adp.SelectCommand = New SqlCommand("SELECT distinct (Session) FROM Session_Master", con)
27 ds = New DataSet("ds")
28 adp.Fill(ds)
29 dtable = ds.Tables(0)
30 cmbSession1.Items.Clear()
31 For Each drow As DataRow In dtable.Rows
32 cmbSession1.Items.Add(drow(0).ToString())
33 Next
34 Catch ex As Exception
35 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
36 End Try
37 End Sub
38
39 Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
40 Me.Close()
41 End Sub
42 Sub Reset()
43 cmbClass.SelectedIndex = -1
44 cmbSession1.SelectedIndex = -1
45 txtClass.Text = ""
46 txtSection.Text = ""
47 txtSectionID.Text = ""
48 cmbSection.SelectedIndex = -1
49 cmbSession.SelectedIndex = -1
50 listView1.Items.Clear()
51 cmbClass.Enabled = False
52 cmbSection.Enabled = False
53 btnUpdate.Enabled = False
54 End Sub
55 Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
56 Reset()
57 End Sub
58
59 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
60 Try
61 If Len(Trim(cmbSession1.Text)) = 0 Then
62 MessageBox.Show("Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
63 cmbSession1.Focus()
64 Exit Sub
65 End If
66 If Len(Trim(txtClass.Text)) = 0 Then
67 MessageBox.Show("Please retrieve class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
68 txtClass.Focus()
69 Exit Sub
70 End If
71 If listView1.Items.Count = 0 Then
72 MessageBox.Show("Sorry nothing to update.." & vbCrLf & "Please retrieve data in listview", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
73 Exit Sub
74 End If
75 For i As Integer = listView1.Items.Count - 1 To 0 Step -1
76
77 If listView1.Items(i).Checked = True Then
78 con = New SqlConnection(cs)
79 Dim cd As String = "update student set Session=@d1,SectionID=" & txtSectionID.Text & " where AdmissionNo=@d2"
80 cmd = New SqlCommand(cd)
81 cmd.Parameters.AddWithValue("@d1", cmbSession1.Text)
82 cmd.Parameters.AddWithValue("@d2", listView1.Items(i).SubItems(0).Text)
83 cmd.Connection = con
84 con.Open()
85 cmd.ExecuteNonQuery()
86 con.Close()
87 End If
88 Next
89 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
90 btnUpdate.Enabled = False
91 Catch ex As Exception
92 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
93 End Try
94 End Sub
95
96
97 Private Sub cmbSession_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSession.SelectedIndexChanged
98 Try
99 cmbClass.Enabled = True
100 con = New SqlConnection(cs)
101 con.Open()
102 Dim ct As String = "SELECT distinct RTRIM(ClassName) FROM Student,Section,Class where Student.SectionID=Section.ID and Section.Class=Class.ClassName and Session=@d1"
103 cmd = New SqlCommand(ct)
104 cmd.Connection = con
105 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
106 rdr = cmd.ExecuteReader()
107 cmbClass.Items.Clear()
108 While rdr.Read
109 cmbClass.Items.Add(rdr(0))
110 End While
111 con.Close()
112 Catch ex As Exception
113 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
114 End Try
115 End Sub
116
117 Private Sub cmbClass_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbClass.SelectedIndexChanged
118 Try
119 cmbSection.Enabled = True
120 con = New SqlConnection(cs)
121 con.Open()
122 Dim ct As String = "SELECT distinct RTRIM(SectionName) FROM Student,Section,Class where Student.SectionID=Section.ID and Section.Class=Class.ClassName and Session=@d1 and ClassName=@d2"
123 cmd = New SqlCommand(ct)
124 cmd.Connection = con
125 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
126 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
127 rdr = cmd.ExecuteReader()
128 cmbSection.Items.Clear()
129 While rdr.Read
130 cmbSection.Items.Add(rdr(0))
131 End While
132 con.Close()
133 Catch ex As Exception
134 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
135 End Try
136 End Sub
137
138 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
139 Try
140 If Len(Trim(cmbSession.Text)) = 0 Then
141 MessageBox.Show("Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
142 cmbSession.Focus()
143 Exit Sub
144 End If
145 If Len(Trim(cmbClass.Text)) = 0 Then
146 MessageBox.Show("Please select class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
147 cmbClass.Focus()
148 Exit Sub
149 End If
150 If Len(Trim(cmbSection.Text)) = 0 Then
151 MessageBox.Show("Please select section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
152 cmbSection.Focus()
153 Exit Sub
154 End If
155 con = New SqlConnection(cs)
156 con.Open()
157 cmd = New SqlCommand("select AdmissionNo,StudentName From from Student,ClassInfo,Section,SchoolInfo where Student.SectionID=Section.ID and ClassInfo.ClassName=Section.Class and SchoolInfo.S_ID=Student.SchoolID and Session=@d1 and ClassName=@d2 and SectionName=@d3 order by StudentName", con)
158 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
159 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
160 cmd.Parameters.AddWithValue("@d3", cmbSection.Text)
161 rdr = cmd.ExecuteReader()
162 While rdr.Read()
163 Dim item = New ListViewItem()
164 item.Text = rdr(0).ToString().Trim()
165 item.SubItems.Add(rdr(1).ToString().Trim())
166 listView1.Items.Add(item)
167 End While
168 Catch ex As Exception
169 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
170 End Try
171 End Sub
172
173 Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
174 Try
175 btnUpdate.Enabled = True
176 If Len(Trim(cmbSession.Text)) = 0 Then
177 MessageBox.Show("Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
178 cmbSession.Focus()
179 Exit Sub
180 End If
181 If Len(Trim(cmbClass.Text)) = 0 Then
182 MessageBox.Show("Please select class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
183 cmbClass.Focus()
184 Exit Sub
185 End If
186 If Len(Trim(cmbSection.Text)) = 0 Then
187 MessageBox.Show("Please select section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
188 cmbSection.Focus()
189 Exit Sub
190 End If
191 con = New SqlConnection(cs)
192 con.Open()
193 cmd = New SqlCommand("select Student.AdmissionNo,StudentName from Student,Class,Section,SchoolInfo where Student.SectionID=Section.ID and Class.ClassName=Section.Class and SchoolInfo.S_ID=Student.SchoolID and Session=@d1 and ClassName=@d2 and SectionName=@d3 and Student.Status='Active' order by StudentName", con)
194 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
195 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
196 cmd.Parameters.AddWithValue("@d3", cmbSection.Text)
197 rdr = cmd.ExecuteReader()
198 While rdr.Read()
199 Dim item = New ListViewItem()
200 item.Text = rdr(0).ToString().Trim()
201 item.SubItems.Add(rdr(1).ToString().Trim())
202 listView1.Items.Add(item)
203 End While
204 Catch ex As Exception
205 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
206 End Try
207 End Sub
208
209 Private Sub frmDiscount_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
210 fillSession()
211 fillSession1()
212 End Sub
213
214 Private Sub BtnClose1_Click(sender As System.Object, e As System.EventArgs)
215 Me.Close()
216 End Sub
217
218 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
219 frmSectionRecord.Reset()
220 frmSectionRecord.lblSet.Text = "Class Transfer"
221 frmSectionRecord.ShowDialog()
222 End Sub
223 End Class